#ifndef NPC_H
#define NPC_H

#include <QNetworkProxy>
#include <QHttp>
#include <QTime>
#include <QTimer>
#include <QObject>
#include <QAbstractTableModel>

///Network Proxy Checker
class npc : public QObject{
    Q_OBJECT
    QNetworkProxy proxy;
    QString _note;
    QTimer * timer;
    QTime * clocker;
    QHttp * target;
    int costTime;
    QString key;
public:
    npc(const QNetworkProxy::ProxyType type= QNetworkProxy::HttpProxy, const QString Host = QString(), int Port = 80, const QString Note = QString(), const QString Name = QString(), const QString Pwd = QString());
    ~npc();
    void start(QString Url, QString key, int sec = 20);
    QString ip() const ;
    QString time(int choose = 1) const;
    QString type() const;
    QString note() const;
    QString save() const;
    bool operator<(const npc & other) const;
public slots:
    void checkKey(bool);
    void timeout();
};

class npcModel : public QAbstractTableModel{
	QList<npc *> * npcs;
    public:
	npcModel(QObject * parent = 0);
	void setSource(QList<npc *> * source);
	int rowCount (const QModelIndex & parent) const;
	int columnCount (const QModelIndex & parent) const;
	QVariant data(const QModelIndex & index, int role) const;
	QVariant headerData(int section, Qt::Orientation oritation, int role) const;
	void fresh();
};

#endif
